package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.service.CatalogService;

import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SearchAjaxServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        String keyword = req.getParameter("keyword");
        keyword = new String(keyword.getBytes("iso-8859-1"),"utf-8");
        CatalogService catalogService = new CatalogService();
        String res = catalogService.SearchAjax(keyword);
        resp.getWriter().write(res);
    }
}
